package four;

abstract class Animal {
    public abstract void move(String destination);
    public abstract void drink();

    protected abstract String getName();
}
abstract class Mammal extends Animal{}   //继承动物类的两个抽象方法，该类为抽象类，不用具体实现
abstract class Raptile extends Animal{}  //继承动物类的两个抽象方法，该类为抽象类，不用具体实现

interface Hunt{
    public abstract void hunt(Animal animal);
}

class Tiger extends Mammal implements Hunt{
    private static String name = "Tiger";
    public String getName(){
        return this.name;
    }

    @Override
    public void move(String destination) {
        System.out.println("Tiger move to "+destination+".");
    }
    @Override
    public void drink() {
        System.out.println("Tiger drink water.");
    }
    public void hunt(Animal animal){
        System.out.println("Tiger catch a " + animal.getName() + " and eat it.");
    }
}

class Snake extends Raptile implements Hunt{
    public static String name = "Snake";
    public String getName(){
        return this.name;
    }

    @Override
    public void move(String destination) {
        System.out.println("Snake move to "+destination+".");
    }
    @Override
    public void drink() {
        System.out.println("Snake drink water.");
    }

    @Override
    public void hunt(Animal animal) {
        System.out.println("Snack catch a " + animal.getName() + " and eat it.");
    }
}
class Rabbit extends Mammal {
    private static String name = "Rabbit";
    public String getName(){
        return this.name;
    }

    @Override
    public void move(String destination) {
        System.out.println("Rabbit move to "+destination+".");
    }
    @Override
    public void drink() {
        System.out.println("Rabbit drink water.");
    }
}
class Farmer {
    void bringWater(String destination){
        System.out.println("Farmer bring water to "+destination);
    }
    void bringAnimal(Animal a,String destination){
        System.out.println("Farmer bring " + a.getName() + " to " + destination + ".");
    }
    void feedWater(Animal animal,String destination){
        this.bringWater(destination);
        animal.move(destination);
        animal.drink();
    }
    void feedAnimal(Hunt hunter,Animal animal){
        this.bringAnimal(animal,"Feeding Room");
        Animal ht = (Animal)hunter;                   // 将传入Hunt的值强制转换成Animal，就可以进行move（）方法
        ht.move("Feeding Room");
        hunter.hunt(animal);
    }
}


public class UseOfInterface {
    public static void main(String[] args) {
        Tiger tiger = new Tiger();
        Snake snake = new Snake();
        Rabbit rabbit = new Rabbit();
        Farmer farmer = new Farmer();

        farmer.feedWater(tiger,"room");
        farmer.feedWater(snake, "grassland");
        farmer.feedWater(rabbit, "kitchen");
        System.out.println("-----------------------");
        farmer.feedAnimal(tiger,rabbit);
    }
}
